package com.service.admin.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.service.admin.base.controller.req.BannerReq;
import com.service.admin.base.controller.req.BannerSaveReq;
import com.service.admin.base.service.BannerService;
import com.service.admin.framework.log.RequestLog;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.MultiResponse;
import com.service.core.rest.response.OneResponse;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.model.Banner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("config/banner")
public class BannerController extends BaseController {

    @Autowired
    private BannerService bannerService;

    @RequestLog("查询列表")
    @PostMapping("/list")
    public MultiResponse<Banner> list(@RequestBody BannerReq bannerReq) {
        return successQueryMultiResponse(bannerService.list(new QueryWrapper<Banner>().lambda()
                .eq(Banner::getBizType, bannerReq.getBizType())
                .eq(Banner::getLanguage, bannerReq.getLanguage())
                .eq(Banner::getBannerStatus, CommonStatusEnums.ACTIVE.getCode())));
    }

    @RequestLog("添加")
    @PostMapping("/save")
    public BaseResponse save(@RequestBody BannerSaveReq bannerSaveReq) {
        bannerService.add(bannerSaveReq);
        return successSaveBaseResponse();
    }

    @RequestLog("更新")
    @PostMapping("/update")
    public BaseResponse update(@RequestBody BannerSaveReq bannerSaveReq) {
        bannerService.update(bannerSaveReq);
        return successSaveBaseResponse();
    }

    @RequestLog("删除")
    @PostMapping("/delete/{id}")
    public BaseResponse update(@PathVariable("id") Integer id) {
        bannerService.deleteBanner(id);
        return successSaveBaseResponse();
    }

    @RequestLog("详情")
    @PostMapping("/detail/{id}")
    public OneResponse<Banner> detail(@PathVariable("id") Integer id) {
        return successQueryOneResponse(bannerService.getById(id));
    }

}
